package com.sjyp.cms.controller.fornt;

import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import com.sjyp.cms.model.Article;
import com.sjyp.cms.model.Picture;

import java.io.File;
import java.util.List;

/**
 * 前端首面
 */
public class IndexController extends Controller {

    public void index() {
        //获取新闻动态
        String newSql = "SELECT t_picture.id,t_picture.`name`,t_picture.summary,t_picture.filePath,t_picture.createDate,t_picture.columnId,t_picture.orderNo " +
                "FROM t_picture " +
                "where columnId=? ORDER BY orderNo";
        List<Picture> news = Picture.dao.find(newSql, 1);
        this.setAttr("news",news);
        //获取关于我们
        String aboutSql = "SELECT t_picture.id,t_picture.`name`,t_picture.summary,t_picture.filePath,t_picture.createDate,t_picture.columnId,t_picture.orderNo " +
                "FROM t_picture " +
                "where columnId=? ORDER BY orderNo";
        Picture aboutPicture = Picture.dao.findFirst(aboutSql, 2);
        String aboutArticleSql = "SELECT t_article.id,t_article.title,t_article.subtitle,t_article.summary,t_article.content,t_article.columnId,t_article.createDate,t_article.orderNo " +
                "FROM t_article " +
                "where columnId=? ORDER BY orderNo";
        Article aboutArticle = Article.dao.findFirst(aboutArticleSql, 2);
        this.setAttr("aboutPicture",aboutPicture);
        this.setAttr("aboutArticle", aboutArticle);
        this.render("index.html");
    }

//    @ActionKey("/about")
//    public void about() {
//        this.render("about.html");
//    }
//
//    @ActionKey("/cases")
//    public void cases() {
//        this.render("cases.html");
//    }
//
//    @ActionKey("/cooperation")
//    public void cooperation() {
//        this.render("cooperation.html");
//    }
//
//    @ActionKey("/dailyChemicals")
//    public void dailyChemicals() {
//        //todo 暂无页面
//        this.render("index.html");
//    }
//
//    @ActionKey("/services")
//    public void services() {
//        //todo 暂无页面
//        this.render("index.html");
//    }
//
//    @ActionKey("/training")
//    public void training() {
//        this.render("training.html");
//    }

    @ActionKey("/img")
    public void upload() {
        String pName = this.getPara("fileName");
        PropKit.use("app.properties");
        String uploadPath = PropKit.get("uploadPath");
        //String uploadPath = "D:\\WorkspacesIDEA\\SJYP-CMS\\SJYP-CMS-web\\target\\SJYP-CMS-web-1.0-SNAPSHOT\\upload\\";
        this.renderFile(new File(uploadPath+pName));
    }
}
